const Actions = require('./actions');
const DB = require('app/db.js');
const { Toast } = SaltUI;
import { monStorage, Storage } from 'clientConfig/util/StoreData';
module.exports = Reflux.createStore({
    listenables: [Actions],
    data: {
        categories: [],
        paypointerStrack: [],
    },

    onFetch: function (params, cb) {//支付管理的进度跟踪
        let t = this;
        let categories = [];
        let paypointerStrack = [];
        let time = " 00:00:00";
        let time1 = " 23:59:59";
        let create_time = new Date(params.startTime).toLocaleDateString() + time;
        let finish_time = new Date(params.endTime).toLocaleDateString() + time1;
        // t.data.paypointerStrack = [66,84,56,29,52,100,76,88,96,70];
        // t.data.categories = ['xx项目','xx项目','xx项目','xx项目','xx项目','xx项目','xx项目','xx项目','xx项目','xx项目'];
        if (params.module_type == "workplan" || params.module_type == "tender") {
            DB.Proj.get_workplan_overview({
                create_time,
                finish_time,
                module_type: params.module_type,
                proj_category: params.proj_category,
                id:Storage.get('user.id')
            }).then((content) => {// 成功
                console.log(content)
                if (params.module_type == "workplan" || params.module_type == "tender") {
                    if (content.list.length > 0) {
                        for (let item of content.list) {
                            categories.push(item.proj_name);
                            paypointerStrack.push(item.proj_com_percent * 100)
                        }
                    }
                }
                t.data.categories = categories;
                t.data.paypointerStrack = paypointerStrack;
                t.updateComponent();
            }).catch((error) => { // 失败 or 有异常被捕获
                Toast.show({
                    type: 'success',
                    content: '未找到项目'
                });
            });
        } else {
            DB.Proj.get_payment_overview({
                create_time,
                finish_time,
                module_type: params.module_type,
                proj_category: params.proj_category,
                id:Storage.get('user.id')
            }).then((content) => {// 成功
                content.list.map((item, index) => {
                    categories.push(item.proj_name);
                    paypointerStrack.push(item.paypointerStrack);
                })
                t.data.categories = categories
                t.data.paypointerStrack = paypointerStrack
                //t.data.paypointerStrack = [0,50,50,50,100,0,0,0,50,50];
                //t.data.categories = ['支付项目1','支付项目2','支付项目3','支付项目4','支付项目5','支付项目6','支付项目7','支付项目8','支付项目9','支付项目10'];
                t.updateComponent();
            }).catch((error) => { // 失败 or 有异常被捕获

            });
        }

    },

    updateComponent: function () {
        console.log(this.data)
        this.trigger(this.data);
    }
});
